package ch.sv7.tool.dbmanager.db.dialect;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import ch.sv7.tool.dbmanager.db.ColumnSchema;
import ch.sv7.tool.dbmanager.db.ColumnType;
import ch.sv7.tool.dbmanager.db.ConstraintSchema;
import ch.sv7.tool.dbmanager.db.ForeignKeySchema;
import ch.sv7.tool.dbmanager.db.IndexSchema;
import ch.sv7.tool.dbmanager.db.TableSchema;
import ch.sv7.tool.dbmanager.types.TypesInfo;

/**
 * This Dialect interface provides all primitive used to modify the
 * datbase structure.
 *
 * @author svt
 *
 */
public interface Dialect {

	public final static char CONVERSION_TYPE_IMPLICIT = 'I';
	public final static char CONVERSION_TYPE_EXPLICIT = 'E';
	public final static char CONVERSION_TYPE_CUSTOM = 'U';
	public final static char CONVERSION_TYPE_SAME = 'S';
	
	public void setProperty(String key, String value);
	public String getProperty(String key);
	
	public String getName();
	
	/**
	 * Generates the table structure DDL
	 * @param schema
	 * @param includePrimaryKeys
	 * @param includeIndexes
	 * @param includeForegnKeys
	 * @param includeConstraints
	 * @return
	 * @throws DialectException
	 */
	public String getTableDDL(TableSchema schema) throws DialectException;
	public String getCompleteTableDDL(TableSchema schema, 
			boolean includePrimaryKeys, 
			boolean includeIndexes, 
			boolean includeForegnKeys,
			boolean includeConstraints) throws DialectException;
	public String getRenameTableDDL(TableSchema schema, String newName) throws DialectException;
	public String getDropTableDDL(TableSchema schema);
	
	/**
	 * @param type
	 * @return
	 * @throws DialectException
	 */
	public String getColumnTypeDDL(ColumnType type, boolean ignoreDefault) throws DialectException;
	
	/**
	 * @param schema
	 * @return
	 * @throws DialectException
	 */
	public String getColumnDDL(ColumnSchema schema, boolean ignoreDefault) throws DialectException;
	public String getRenameColumnDDL(ColumnSchema schema, String newName) throws DialectException;
	public String getAddColumnDDL(ColumnSchema schema) throws DialectException;
	public String getUpdateColumnDDL(ColumnSchema schema, boolean ignoreDefault) throws DialectException;

	
	public String getAddIndexDDL(IndexSchema index) throws DialectException;
	public String getRenameIndexDDL(IndexSchema index, String newName) throws DialectException;
	public String getDropIndexDDL(IndexSchema index) throws DialectException;
	
	public String getAddForeignKeyDDL(ForeignKeySchema fk) throws DialectException;
	public String getRenameForeignKeyDDL(ForeignKeySchema fk, String newName) throws DialectException;
	public String getDropForeignKeyDDL(ForeignKeySchema fk) throws DialectException;
	
	public String getAddConstraintDDL(ConstraintSchema constraint) throws DialectException;
	public String getDropConstraintDDL(ConstraintSchema constraint) throws DialectException;
	
	public String getFixNullValuesSQL(ColumnSchema schema) throws DialectException;
	
	public String getStatementDelimiter() throws DialectException;
	
	public TypesInfo getTypesInfo() throws DialectException;
	
	public String getDefaultTypeName(String jdbcTypeName);
	
	public char getDataTypeConversion(String fromType, String toType);
	
	public void readDatabaseSpecificInformation(TableSchema tableSchema, Connection conn) throws DialectException;

	public boolean isRealError(SQLException e);
	public String getDisableAutoIncrementDDL(ColumnSchema schema);
	public String getEnableAutoIncrementDDL(ColumnSchema schema);
	
	public Properties getContextProperties();
}
